package com.nabisoft.jaxrs.application;

import com.nabisoft.tutorials.mavenstruts.service.MessageService;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import org.apache.log4j.Logger;

@ApplicationPath("/")
public class ApplicationConfig extends Application {
    
    private static final Logger LOGGER = Logger.getLogger(MessageService.class);

    @Override
    public Set<Class<?>> getClasses() {
        
        Set<Class<?>> resources = new java.util.HashSet<>();
        
        LOGGER.debug("REST configuration starting: getClasses()");            
        
        //features
        //this we will register Jackson JSON providers
        resources.add(org.glassfish.jersey.jackson.JacksonFeature.class);
        //but we could also register them manually:
        //resources.add(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider.class);
        
        
        //we don't want everything added by netbeans.
        //unfortunately you cannot configure in the netbeans ide what you want and what not
        //addRestResourceClasses(resources);
        
        //instead let's do it manually:
        resources.add(com.nabisoft.jaxrs.provider.MyJacksonJsonProvider.class);
        resources.add(com.nabisoft.tutorials.mavenstruts.service.MessageService.class);
        
        LOGGER.debug("REST configuration ended successfully.");
        
        return resources;
    }
    
    @Override
    public Set<Object> getSingletons() {
        return Collections.emptySet();
    }
    
    @Override
    public Map<String, Object> getProperties() {
        Map<String, Object> properties = new HashMap<>();
        
        //in Jersey WADL generation is enabled by default, but we don't 
        //want to expose too much information about our apis.
        //therefore we want to disable wadl (http://localhost:8080/service/application.wadl should return http 404)
        //see https://jersey.java.net/nonav/documentation/latest/user-guide.html#d0e9020 for details
        properties.put("jersey.config.server.wadl.disableWadl", true);
        
        //we could also use something like this instead of adding each of our resources
        //explicitely in getClasses():
        //properties.put("jersey.config.server.provider.packages", "com.nabisoft.tutorials.mavenstruts.service");
        
        
        return properties;
    }

    /**
     * Do not modify addRestResourceClasses() method.
     * It is automatically re-generated by NetBeans REST support to populate
     * given list with all resources defined in the project.
     */
    private void addRestResourceClasses(Set<Class<?>> resources) {
        resources.add(com.nabisoft.jaxrs.provider.MyJacksonJsonProvider.class);
        resources.add(com.nabisoft.tutorials.mavenstruts.service.MessageService.class);
    }
    
}